//
//  AddressBookViewController.m
//  MobileOffice
//
//  Created by jjkj on 16/10/24.
//  Copyright © 2016年 liaoningjujin. All rights reserved.
//

#import "AddressBookViewController.h"
#import "AddressBooksTableViewCell.h"
#import "AddressModel.h"
#import "AddressSearchModel.h"
#import "AddressDetailViewController.h"
#import "PersonMessageViewController.h"
#import "StatisticsTableViewCell.h"
#import "TaskDetailViewController.h"

#define getAddressList @"getAddressList"
#define getDepartEmpName_all @"getDepartEmpName_all"

#define EDGEINSET 6
#define TOPINSET 6


@interface AddressBookViewController ()<UITableViewDelegate,UITableViewDataSource,UISearchBarDelegate,UIGestureRecognizerDelegate>
{
    UITableView *_tableView;//列表
    //UIButton * _grayButton;
    UIView * _searchView;//搜索框
    UITableView *_searchTableView;//搜索结果列表
    AddressSearchModel *_searchListModel;//搜索结果列表model
    UIView *_searchBackView;//搜索view

}
@property (nonatomic,strong) NSArray *searchArr;//筛选数组
@property (nonatomic,strong) AddressModel *model;//列表model
@property (nonatomic,strong) UIScrollView *userScrollView;//用户当前操作的scrollView
@property (nonatomic,strong) UISearchBar * searchBar;
@property (nonatomic,strong)UITableView *infoTableView;//筛选tableView
@property (nonatomic,strong)UIView *tableBackView;
@end

@implementation AddressBookViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setNavigationTitle:@"员工动态"];
    [self setRightBackNavigation];
    [self setLeftBackNavigation];
    [self createSearchViewWithView];
    [self creatView];
    //为空默认搜索全部
    [self addressListRequestWithName:nil empState:nil];
    // Do any additional setup after loading the view.
}

#pragma mark - creatTableView
- (void)creatView{
    _tableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 40, IPHONE_WIDTH, IPHONE_HEIGHT-64-40) style:UITableViewStylePlain];
    //_myTableView.backgroundColor=[UIColor redColor];
    _tableView.delegate=self;
    _tableView.dataSource=self;
    _tableView.tag=110;
    _tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
    _tableView.showsVerticalScrollIndicator=NO;
    _tableView.showsHorizontalScrollIndicator=NO;
    //[self addTableViewUpdateRefresh:self.tableView BindingIdentity:@""];
    //    [self addTableViewLoadMoreData:_tableView BindingIdentity:@""];
    [self.view addSubview:_tableView];

    //    self.definesPresentationContext = YES;
}

- (void)creatSearchTableView{
    _searchBackView=[[UIView alloc]initWithFrame:CGRectMake(0, 40, IPHONE_WIDTH, IPHONE_HEIGHT-64-40)];
    _searchBackView.backgroundColor=[UIColor clearColor];
    [self.view addSubview:_searchBackView];
    
    UIView *alphaView=[[UIView alloc]initWithFrame:CGRectMake(0, 40, IPHONE_WIDTH, IPHONE_HEIGHT-64-40)];
    alphaView.alpha=0.4;
    alphaView.backgroundColor=[UIColor blackColor];
    [_searchBackView addSubview:alphaView];
    
    //点击手势
    UITapGestureRecognizer * tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(TwoTapGestureRecognizer:)];
    tapGesture.delegate=self;
    [tapGesture setNumberOfTapsRequired:1];
    [tapGesture setNumberOfTouchesRequired:1];
    [alphaView addGestureRecognizer:tapGesture];
    
    _searchTableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, IPHONE_WIDTH, 250) style:UITableViewStylePlain];
    //_searchTableView.backgroundColor=[UIColor clearColor];
    _searchTableView.delegate=self;
    _searchTableView.dataSource=self;
    _searchTableView.tag=111;
    _searchTableView.separatorStyle=UITableViewCellSeparatorStyleNone;
    //[self addTableViewUpdateRefresh:self.tableView BindingIdentity:@""];
    //    [self addTableViewLoadMoreData:_tableView BindingIdentity:@""];
    [_searchBackView addSubview:_searchTableView];

}

#pragma mark -取消手势
-(void)TwoTapGestureRecognizer:(UIGestureRecognizer*)gr{
    
    if (_searchBackView) {
        [_searchBackView removeFromSuperview];
        _searchBackView=nil;
    }
    if (_tableBackView) {
        [_tableBackView removeFromSuperview];
        _tableBackView=nil;
    }
    
}



#pragma mark - creatSearchBar
-(void)createSearchViewWithView{
    self.searchArr=@[@"全部",@"工作中",@"迟到",@"旷工",@"午休中",@"早退",@"休息中",@"未签退",@"请假中",@"公出中"];
    //    if (_searchView) {
    //        //防止搜索按钮多次被点击
    //        return;
    //    }
    _pageNum=@"1";
//    _grayButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 64, IPHONE_WIDTH, IPHONE_HEIGHT-64)];
//    [_grayButton setBackgroundColor:COLOR(106, 107, 108, 0.7)];
//    [_grayButton addTarget:self action:@selector(cancelSearch:) forControlEvents:UIControlEventTouchUpInside];
//    [self.view addSubview:_grayButton];
    //搜索框
    _searchView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, IPHONE_WIDTH, 40)];
    _searchView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:_searchView];
    //textField
    
    //筛选按钮
    UIButton *selectBtn=[MyControl creatButtonWithFrame:CGRectMake(0, 0, 70, 40) target:self sel:@selector(selectBtnClick:) tag:100 image:nil title:self.searchArr[0]];
    selectBtn.backgroundColor=[UIColor whiteColor];
    selectBtn.layer.borderColor=[[UIColor lightGrayColor]CGColor];
    selectBtn.layer.borderWidth=0.5f;
    [selectBtn setImage:[UIImage imageNamed:@"k_ic_xl@2x"] forState:UIControlStateNormal];
    [selectBtn setImage:[UIImage imageNamed:@"k_ic_sl@2x"] forState:UIControlStateSelected];
    //调整文字和图片的位置
    [selectBtn setTitleEdgeInsets:UIEdgeInsetsMake(0,-selectBtn.imageView.width, 0, selectBtn.imageView.width)];
    [selectBtn setImageEdgeInsets:UIEdgeInsetsMake(0, selectBtn.titleLabel.width+20, 0, -selectBtn.titleLabel.width)];
    [_searchView addSubview:selectBtn];
    
    _searchBar = [[UISearchBar alloc]initWithFrame:CGRectMake(71, 0, IPHONE_WIDTH-50-71, 40)];
    _searchBar.placeholder = @"请输入搜索内容";
//    _searchBar.borderStyle = UITextBorderStyleRoundedRect;
//    _searchBar.font = FONT_14;
//    _searchBar.clearButtonMode = UITextFieldViewModeWhileEditing;
    _searchBar.delegate = self;
    _searchBar.searchBarStyle=UISearchBarStyleMinimal;
    _searchBar.returnKeyType = UIReturnKeyGo;
    [_searchView addSubview:_searchBar];
    //startSearchButton
    
    //搜索按钮
    UIButton * searchButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [searchButton setTitle:@"搜索" forState:UIControlStateNormal];
    [searchButton setTitleColor:COLOR_MIDBLUE forState:UIControlStateNormal];
    searchButton.titleLabel.font = FONT_14;
    [_searchView addSubview:searchButton];
    //[searchButton setBackgroundColor:[UIColor yellowColor]];
    searchButton.frame = CGRectMake(_searchBar.x+_searchBar.width, _searchBar.y, IPHONE_WIDTH-(_searchBar.x+_searchBar.width), 40);
    searchButton.layer.cornerRadius = 8;
    searchButton.layer.masksToBounds = YES;
    [searchButton addTarget:self action:@selector(beginSearchItemsForTableView) forControlEvents:UIControlEventTouchUpInside];
    //    [self.view addSubview:searchView];
    
}

#pragma mark - 筛选列表
- (void)creatInfoTableView{
    if (_tableBackView) {
        return;
    }
    CGFloat height=0;
    //计算tableView的高
    height=self.searchArr.count*44;
    
    if (height>IPHONE_HEIGHT-64-40) {
        height=IPHONE_HEIGHT-64-40;
    }
    _tableBackView=[[UIView alloc]initWithFrame:CGRectMake(0, 40, IPHONE_WIDTH, IPHONE_HEIGHT-64-40)];
    //    [self.view insertSubview:_tableBackView aboveSubview:self.view];
    _tableBackView.backgroundColor=[UIColor clearColor];
    [self.view addSubview:_tableBackView];
    
    UIView *alphaView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, IPHONE_WIDTH, _tableBackView.height)];
    alphaView.alpha=0.4;
    alphaView.backgroundColor=[UIColor blackColor];
    [_tableBackView addSubview:alphaView];
    
    //点击手势
    UITapGestureRecognizer * tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(TwoTapGestureRecognizer:)];
    tapGesture.delegate=self;
    [tapGesture setNumberOfTapsRequired:1];
    [tapGesture setNumberOfTouchesRequired:1];
    [alphaView addGestureRecognizer:tapGesture];
    
    _infoTableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, IPHONE_WIDTH,height) style:UITableViewStylePlain];
    //_myTableView.backgroundColor=[UIColor redColor];
    _infoTableView.delegate=self;
    _infoTableView.dataSource=self;
    _infoTableView.tag=112;
    _infoTableView.bounces=NO;
    _infoTableView.separatorStyle=UITableViewCellSeparatorStyleNone;
    _infoTableView.showsVerticalScrollIndicator=NO;
    _infoTableView.showsHorizontalScrollIndicator=NO;
    //[self addTableViewUpdateRefresh:_tableView BindingIdentity:@""];
    //    [self addTableViewLoadMoreData:_tableView BindingIdentity:@""];
    [_tableBackView addSubview:_infoTableView];
    
    //    [UIView animateWithDuration:0.2 animations:^{
    //        _tableBackView.y=64+80;
    //    }];
    //    self.definesPresentationContext = YES;
}

#pragma mark -筛选按钮
- (void)selectBtnClick:(UIButton *)selectButton{
    selectButton.selected=!selectButton.selected;
    //根据开关状态 是否打开选择页面
    if (selectButton.selected) {
        if (!_tableBackView) {
            [self creatInfoTableView];
        }
        //                [self refreshSelectViewWithSelectNum:selectButton.tag-100];
    }else{
        [_tableBackView removeFromSuperview];
        _tableBackView=nil;
    }
}

#pragma mark - 搜索按钮
- (void)beginSearchItemsForTableView{
//    if (_searchBar.text.length==0) {
//        return;
//    }
    [self.view endEditing:YES];
    [self addressSearchRequest];
}

#pragma mark - scrollViewDelegate

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
//    [_tableView reloadData];
    [self.view endEditing:YES];
    if (_userScrollView) {
        [UIView animateWithDuration:0.1 animations:^{
            _userScrollView.contentOffset=CGPointMake(0, 0);
        }];
    }
}


#pragma mark - TableViewDelagate

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (tableView.tag==110) {
         return _model.dataArr.count;
    }else if(tableView.tag==111){
        return _searchListModel.dataArr.count;
    }else{
        return self.searchArr.count;
    }
    //    return _newsListModel.dataArr.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (tableView.tag==110) {
        AddressModel *model=_model.dataArr[indexPath.row];
        NSString *cellID=@"AddressBookTableViewCell";
        AddressBooksTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellID];
        __weak AddressBookViewController * mySelf=self;
        if (!cell) {
            cell=[[AddressBooksTableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellID isLeader:[model.isSafe isEqualToString:@"1"]?YES:NO];
            cell.selectionStyle=UITableViewCellSelectionStyleNone;
            
            //将用户正在操作的scrollView传过来 方便后面操作
            cell.myBlock=^(UIScrollView *scrollView){
                if (mySelf.userScrollView) {
                    //当用户操作的不是同一个scrollView时将上一个回滚
                    if (mySelf.userScrollView!=scrollView) {
                        [UIView animateWithDuration:0.1 animations:^{
                            mySelf.userScrollView.contentOffset=CGPointMake(0, 0);
                        }];
                    }
                }
                mySelf.userScrollView=scrollView;
            };
            
            cell.clickBlock=^(NSInteger row){
                AddressModel *model=mySelf.model.dataArr[row];
                AddressDetailViewController *detail=[AddressDetailViewController new];
                detail.respName=model.empName?[model.empName copy]:@"";
                detail.respId=model.empId?[model.empId copy]:@"";
                detail.postName=model.postName?[model.postName copy]:@"";
                detail.departName=model.departName?[model.departName copy]:@"";
                detail.icon=model.icon?[model.icon copy]:@"";
                detail.isSafe=model.isSafe?[model.isSafe copy]:@"";
                detail.mailbox=model.mailbox?[model.mailbox copy]:@"";
                detail.phone=model.phone?[model.phone copy]:@"";
                [mySelf.navigationController pushViewController:detail animated:YES];
            };
        }
        [cell.headImageView setImageWithURL:[NSURL URLWithString:model.icon] placeholderImage:[UIImage imageNamed:@"k_portrait@2x.png"]];
        cell.nameLabel.text=[NSString stringWithFormat:@"%@(%@)",model.empName,model.departName];
        cell.jobLabel.text=model.postName;
        cell.row=indexPath.row;
        
        cell.statusButton.tag=1000+indexPath.row;
        NSArray *infoArr=[model.empCurrentState componentsSeparatedByString:@"&"];
        //工作状态点击事件
        [cell.statusButton addTarget:self action:@selector(cellButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        if ([infoArr[0] isEqualToString:@"午休中"]||[infoArr[0] isEqualToString:@"休息中"]) {
            //[cell.statusButton setTitle:@"休息中" forState:UIControlStateNormal];
            [cell.statusImageView setImage:[UIImage imageNamed:@"k_ic_ts_xxz@2x"]];
        }else if ([infoArr[0] isEqualToString:@"迟到"]||[infoArr[0] isEqualToString:@"早退"]||[infoArr[0] isEqualToString:@"旷工"]||[infoArr[0] isEqualToString:@"未签到"]){
            //[cell.statusButton setTitle:@"请假中" forState:UIControlStateNormal];
            [cell.statusImageView setImage:[UIImage imageNamed:@"k_ic_ts_qjz@2x"]];
        }else if ([infoArr[0] isEqualToString:@"公出中"]){
            //[cell.statusButton setTitle:@"公出中" forState:UIControlStateNormal];
            [cell.statusImageView setImage:[UIImage imageNamed:@"k_ic_ts_gcz@2x"]];
        }else if ([infoArr[0] isEqualToString:@"请假中"]){
            //[cell.statusButton setTitle:@"加班中" forState:UIControlStateNormal];
            [cell.statusImageView setImage:[UIImage imageNamed:@"k_ic_ts_jbz@2x"]];
        }else if ([infoArr[0] isEqualToString:@"工作中"]){
            //[cell.statusButton setTitle:@"工作中" forState:UIControlStateNormal];
            [cell.statusImageView setImage:[UIImage imageNamed:@"k_ic_ts_gzz@2x"]];
        }else{
            //[cell.statusButton setTitle:@"午休中" forState:UIControlStateNormal];
            [cell.statusImageView setImage:[UIImage imageNamed:@"k_ic_ts_xxz@2x"]];
        }

        [cell.statusButton setTitle:infoArr[0] forState:UIControlStateNormal];
        cell.msgButton.tag=5000+indexPath.row;
        cell.phoneButton.tag=6000+indexPath.row;
        cell.smsButton.tag=7000+indexPath.row;
        //消息点击事件
        [cell.msgButton addTarget:self action:@selector(msgButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        [cell.phoneButton addTarget:self action:@selector(phoneButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        [cell.smsButton addTarget:self action:@selector(smsButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        return cell;

    }else if(tableView.tag==111){
        //搜索结果列表
        NSString *cellID=@"cellID";
        UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellID];
        if (!cell) {
            cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellID];
            UILabel *line=[[UILabel alloc]initWithFrame:CGRectMake(0, 43, IPHONE_WIDTH, 1)];
            line.backgroundColor=BACKCOLOR_GRAY;
            [cell.contentView addSubview:line];
        }
        AddressSearchModel *searchModel=_searchListModel.dataArr[indexPath.row];
        cell.textLabel.text=searchModel.respName;
        return cell;
    }else{
        //筛选条件
        NSString *cellID=@"StatisticsTableViewCell";
        StatisticsTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellID];
        if (!cell) {
            cell=[[StatisticsTableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellID];
            //        cell.selectionStyle=UITableViewCellSelectionStyleNone;
        }
        cell.messageLabel.text=self.searchArr[indexPath.row];
        return cell;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (tableView.tag==110) {
        return 80;
    }else{
        return 44;
    }
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (tableView.tag==110) {

    }else if(tableView.tag==111){
        AddressSearchModel *searchModel=_searchListModel.dataArr[indexPath.row];
        [self addressListRequestWithName:searchModel.respName empState:nil];
        //搜索的时候移除掉searchBackView
        if (_searchBackView) {
            [_searchBackView removeFromSuperview];
            _searchBackView=nil;
        }
    }else{
        //更改当前的搜索条件
        UIButton *selectBtn=(UIButton *)[_searchView viewWithTag:100];
        selectBtn.selected=NO;
        [selectBtn setTitle:self.searchArr[indexPath.row] forState:UIControlStateNormal];
        [selectBtn setTitleEdgeInsets:UIEdgeInsetsMake(0,-selectBtn.imageView.width, 0, selectBtn.imageView.width)];
        [selectBtn setImageEdgeInsets:UIEdgeInsetsMake(0, selectBtn.titleLabel.width+10, 0, -selectBtn.titleLabel.width)];
        if (indexPath.row==0) {
            [self addressListRequestWithName:nil empState:nil];
        }else{
            [self addressListRequestWithName:nil empState:[NSString stringWithFormat:@"%ld",(long)indexPath.row]];
        }

        if (_tableBackView) {
            [_tableBackView removeFromSuperview];
            _tableBackView=nil;
        }
    }
}

-(BOOL)tableView:(UITableView *) tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    //打开编辑
    return NO;
}

#pragma mark -点击事件
//人员状态点击
- (void)cellButtonClick:(UIButton *)button{
    AddressModel *model=_model.dataArr[button.tag-1000];
    NSArray *infoArr=[model.empCurrentState componentsSeparatedByString:@"&"];
    if (infoArr.count>1) {
        TaskDetailViewController *detail=[TaskDetailViewController new];
        //detail.jobState=self.jobState;
        detail.businessCode=infoArr[5];
        detail.vacateBillId=infoArr[4];
        //detail.sex=model.empSex;
        detail.isOperate=@"0";
        //detail.dealState=model.dealState;
        //detail.isOwn=model.isOwn;
        //    if (timeArr.count>1) {
        //        detail.beginStr=timeArr[0];
        //        detail.endStr=timeArr[1];
        //    }
        [self.navigationController pushViewController:detail animated:YES];
    }
}
//消息点击
- (void)msgButtonClick:(UIButton *)button{
    AddressModel *model=_model.dataArr[button.tag-5000];
    PersonMessageViewController *person=[PersonMessageViewController new];
    person.receEmpName=[model.empName copy];
    person.receEmpId=[model.empId copy];
    [self.navigationController pushViewController:person animated:YES];
}

//电话点击
- (void)phoneButtonClick:(UIButton *)button{
    AddressModel *model=_model.dataArr[button.tag-6000];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel://%@",model.phone]]];
}

//短信点击
- (void)smsButtonClick:(UIButton *)button{
    AddressModel *model=_model.dataArr[button.tag-7000];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"sms://%@",model.phone]]];
}
/*
 
打印视图层次，这是一个私有的方法
#ifdef DEBUG
NSLog(@"Cell recursive description:\n\n%@\n\n", [cell performSelector:@selector(recursiveDescription)]);
#endif
*/

//- (NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
//{
//    UITableViewRowAction *likeAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"喜欢" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
//        // 实现相关的逻辑代码
//        // ...
//        // 在最后希望cell可以自动回到默认状态，所以需要退出编辑模式
//        tableView.editing = NO;
//    }];
//    
//    UITableViewRowAction *deleteAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"删除" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
//        // 首先改变model
////        [self.books removeObjectAtIndex:indexPath.row];
////        // 接着刷新view
////        [self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
//        // 不需要主动退出编辑模式，上面更新view的操作完成后就会自动退出编辑模式
//    }];
//    return @[deleteAction, likeAction];
//}





#pragma mark -通讯录列表请求

- (void)addressListRequestWithName:(NSString *)name empState:(NSString *)empState{
    [LZXHelper postLoadViewWithText:HUD_PLEASEWAIT View:self.view];
    NSDictionary *dict=@{
                         @"name":name?name:@"",
                         @"isDepart":@"0",
                         @"empState":empState?empState:@""
                         };
    
    //   字典转json
    NSData* jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:nil];
    NSString* str = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    //拼接soap字符串
    NSString* soap = [NSString stringWithFormat:@"<sessionId>%@</sessionId>\n<content>%@</content>",[LZXHelper getSessionID],str];
   // __weak AddressBookViewController *mySelf=self;
    [HttpRequest SOAPData:[LZXHelper getServerURL] SoapMthod:getAddressList soapBody:soap success:^(id responseObject) {
        [LZXHelper hideLoadViewWithView:self.view];
        
        //解析数据
         _model=[[AddressModel alloc]initWithResponse:responseObject];
        if ([_model.code isEqualToString:@"200"]) {
            [_tableView reloadData];
        }else if([_model.code isEqualToString:@"220"]){
            [LZXHelper postMessageWithText:_model.msg View:self.view];
        }
    } failure:^(NSError *error) {
        [LZXHelper hideLoadViewWithView:self.view];
    }];
}
#pragma mark -搜索请求
- (void)addressSearchRequest{
    NSDictionary *dict=@{
                         @"isDepartOrEmp":@"2",
                         @"inputValue":_searchBar.text,
                         };
    
    //   字典转json
    NSData* jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:nil];
    NSString* str = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    //拼接soap字符串
    NSString* soap = [NSString stringWithFormat:@"<sessionId>%@</sessionId>\n<content>%@</content>",[LZXHelper getSessionID],str];
    [LZXHelper postLoadViewWithText:HUD_PLEASEWAIT View:self.view];
    // __weak AddressBookViewController *mySelf=self;
    [HttpRequest SOAPData:[LZXHelper getServerURL] SoapMthod:getDepartEmpName_all soapBody:soap success:^(id responseObject) {
        [LZXHelper hideLoadViewWithView:self.view];
        
        //解析数据
        _searchListModel=[[AddressSearchModel alloc]initWithResponse:responseObject];
        if ([_searchListModel.code isEqualToString:@"200"]) {
            if (!_searchBackView) {
                [self creatSearchTableView];
            }else{
                [_searchTableView reloadData];
            }
            if (_searchListModel.dataArr.count==0) {
                //增加提示语
                [self addReminderViewWithFrame:_searchTableView.frame msg:@"没有搜索到该员工！" backView:_searchTableView];
            }else{
                //移除提示语
                [self removeReminderView];
            }
        }else if([_searchListModel.code isEqualToString:@"220"]){
            [LZXHelper postMessageWithText:_searchListModel.msg View:self.view];
        }
    } failure:^(NSError *error) {
        [LZXHelper hideLoadViewWithView:self.view];
    }];
}

#pragma mark -searchBarDelegate

- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{
    [self beginSearchItemsForTableView];
}
//
//#pragma mark ----UITextFieldDelegate
//-(void)textFieldDidEndEditing:(UITextField *)textField{
//    [textField resignFirstResponder];
//}
//-(BOOL)textFieldShouldReturn:(UITextField *)textField{
//    //    [textField resignFirstResponder];
//    [self beginSearchItemsForTableView];
//    //这里也可以进行return后的操作。
//    
//    return YES;
//}
//-(BOOL)textFieldShouldClear:(UITextField *)textField{
//    return YES;
//}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
